import {exec} from "child_process";
import logger from "../tools/logger";

interface typeProcessEvn {
    [key: string]: boolean | string,

    "-dev": boolean,
    language: string
}

const processEvnConfig: typeProcessEvn = {
    "-dev": false,
    language: "en-US"
}
const processEvn = process.argv.slice(2);


function getWindowsLanguage():Promise<string> {
    return new Promise((resolve)=>{
        exec('wmic os get MUILanguages', (error, stdout, stderr) => {
            if (error) {
                logger.error(`getWindowsLanguage error: ${error}`);
                return;
            }
            const language = stdout.trim().split('\n')[1].trim().split('"')[1];
            resolve(language)
        });
    })

}
/**
 * 返回的evn为true 检测这条命令行是否被调用
 */
export default function () {
    getWindowsLanguage().then(language=>{
        processEvnConfig.language = language
    })
    processEvn.forEach(arg => {
        if (arg in processEvnConfig) {
            processEvnConfig[arg] = true;
        }
    });
    return processEvnConfig
}

export {getWindowsLanguage}